package com.mspbots.api.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.mspbots.api.service.SheetsTimesService;
import com.mspbots.cw.request.SheetsTimeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.Map;

import static java.time.temporal.ChronoUnit.SECONDS;

/**
 * com.mspbots.api.service.impl.TSheetTimesServiceImpl
 *
 * @author Jun Zhou
 * @date 11:05 2019/7/26
 **/
@Deprecated
@Slf4j
@Service
public class SheetsTimesServiceImpl extends BaseGenericService implements SheetsTimesService {


    @Override
    public List<SheetsTimeDTO> findList(Map<String, Object> params) {
        try {
            Mono<JsonNode> resultMono = this.apiClient.get("/sheet-times/analysis-list", params);
            JsonNode result = resultMono.block(Duration.of(5, SECONDS));
            return this.objectMapper.convertValue(result, new TypeReference<List<SheetsTimeDTO>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return null;
    }

}
